
<script type="text/html" template>
    <link rel="stylesheet" href="{{ layui.setter.base }}style/login.css?v={{ layui.admin.v }}-1" media="all">
</script>
  <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div class="layadmin-user-login-main">
      <div class="layadmin-user-login-box layadmin-user-login-header">
      </div>
      <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
        <div class="layui-inner-form">
            <div class="layui-form-item" style="margin-bottom: 23px;">
                <label class="layadmin-user-login-icon layui-icon lay-icon-username" for="LAY-user-login-username"></label>
                <input type="text" name="username" id="LAY-user-login-username" lay-verify="required" placeholder="用户名" class="layui-input">
            </div>
            <div class="layui-form-item" style="margin-bottom: 17px;">
                <label class="layadmin-user-login-icon layui-icon lay-icon-password" for="LAY-user-login-password"></label>
                <input type="password" name="password" id="LAY-user-login-password" lay-verify="required" placeholder="密码" class="layui-input lay-ipt-pwd">
            </div>
            <div class="layui-form-item lay-ipt-remember" style="margin-bottom: 20px;">
                <input type="checkbox" name="remember" lay-skin="primary" title="记住密码">
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid lay-btn-submit" lay-submit lay-filter="LAY-user-login-submit">登录</button>
            </div>
        </div>
      </div>
    </div>
  </div>

  <style>
      body{
        background: url('../../../../dist/style/res/user/loginBg.png')  center center no-repeat;
        height: 100%;
      }
      .layadmin-user-login .layadmin-user-login-main{
          width: 603px;
      }
      .layadmin-user-login-box{
          padding: 0;
      }
      .layadmin-user-login-header{
        position: relative;
        width: 603px;
        height: 87px;
        background: url('../../../../dist/style/res/user/logo-header.png')  center center no-repeat;
      }
      .login-header-logo{
        position: absolute;
        top: 0;
        left:0;
        width: 87px;
        height: 100%;
        background: url('../../../../dist/style/res/logo.png')  center center no-repeat;
      }
      .login-header-text{
        position: absolute;
        top: 0;
        right: 0;
        position: absolute;
        width: 516px;
        height: 100%;
        color: #fff;
        font-size: 40px;
        line-height: 87px;
        text-shadow: 0.1em 0.1em 0.2em #000;
        letter-spacing: 3px;
        text-align: right;
      }
      .layadmin-user-login-body{
          width: 540px;
          height: 320px;
          margin: 49px auto 0;
          background: url('../../../../dist/style/res/user/login-bg.png') center center no-repeat;
      }
      .layui-inner-form{
        width: 301px;
        height: 100%;
        margin: 0 auto;
        padding-top: 55px;
      }
      .layui-form-item{
          margin-bottom: 0;
      }
      .layui-form-item .layui-form-checkbox[lay-skin=primary], 
      .layui-form-item .layui-form-checkbox[lay-skin=primary]{
        margin-top: 0;
      }
      .lay-btn-submit{
        background-color: #2E7FCD;
      }
      .lay-icon-password,  .lay-icon-username{
        height: 36px;
      }
      .lay-icon-username{
        background: url('../../../../dist/style/res/user/user-login.png') center center no-repeat;
      }
      .lay-icon-password{
        background: url('../../../../dist/style/res/user/user-pwd.png') center center no-repeat;
      }
      .layui-form-checked[lay-skin=primary] i{
        border-color: #317ECC;
        background-color: #317ECC;
      }
  </style>
  
  <script>
  layui.use(['admin', 'form', 'user'], function(){
    var $ = layui.$
    ,setter = layui.setter
    ,admin = layui.admin
    ,form = layui.form
    ,router = layui.router()
    ,search = router.search,
    flag = false;
  
    form.render();
  
    //请求登录
    form.on('submit(LAY-user-login-submit)', function(obj){
      var username = $.trim(obj.field.username),
          password = $.trim(obj.field.password);
      admin.req({
        url: 'myapi/DC/login' 
        ,data: {
          cert_code: username,
          password: password
        }
        ,done: function(res){
           //请求成功后，写入 access_token
           if(res.retcode == 0){
              layui.data(setter.tableName, {
                  key: setter.request.tokenName
                  ,value: res.jsonId
              });
              //请求成功写入用户信息
              layui.data('userdata', {
                key: 'data',
                value: res.data
              });

              //登入成功的提示与跳转
              layer.msg('登录成功', {
                offset: '15px' 
                ,icon: 1
                ,time: 1000
              }, function(){ 
                
                sessionStorage.setItem("userdata",JSON.stringify(res.data));
                location.hash = '/user/homeIndex';
                layer.closeAll();
              });
            }
        }
      });
    });
 
    //按钮绑定回车事件
    $(document).unbind('keydown'); //避免多次键盘事件

    $(document).keydown(function(e){ //键盘按下时触发
      if(flag){
        return;
      }
      flag = true;
      if(e.keyCode == '13'){
        $('.lay-btn-submit').click();
      }
    })

    $(document).keyup(function(e){ //键盘松开时触发
        flag = false;
    })
    
  });
  </script>